﻿<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:System="clr-namespace:System;assembly=mscorlib" 
    xmlns:coll="clr-namespace:System.Collections;assembly=mscorlib"
             xmlns:Theme="clr-namespace:OMANE.Common.UI.Theme;assembly=OMANE.Common.UI.Theme"
             xmlns:VMtxgar="clr-namespace:OMANE.Modules.TauxGarantis.ViewModels" 
     xmlns:local="clr-namespace:OMANE.Modules.TauxGarantis"
             xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" 
             xmlns:txGar="clr-namespace:OMANE.Modules.TauxGarantis"
    DataContext="{Binding Source={x:Static VMtxgar:Locator.ViewModelGarantiesDecesPtiaStatic}}"
    x:Class="Views.ViewGarantiesDecesPtia"  
             mc:Ignorable="d" 
           >
    <UserControl.Resources>
        <txGar:ColumnToVisibilityConverter x:Key="ColumnToVisibilityConverter" />
        <HorizontalAlignment x:Key="EntryLabelHorizontalAlignment">Right</HorizontalAlignment>
        <Thickness x:Key="EntryLabelMargin">0,0,5,0</Thickness>
        <VerticalAlignment x:Key="EntryLabelVerticalAlignment">Center</VerticalAlignment>
        <Thickness x:Key="EntryGridMargin">0,2</Thickness>
        <HorizontalAlignment x:Key="EntryValueHorizontalAlignment">Left</HorizontalAlignment>
        <Thickness x:Key="EntryValueMargin">5,0,0,0</Thickness>
        <VerticalAlignment x:Key="EntryValueVerticalAlignment">Center</VerticalAlignment>
        <System:Double x:Key="EntryValueWidth">149</System:Double>
    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="10"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="10"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <GroupBox Style="{DynamicResource OMANE_GpeBox}" Header="Garanties Deces / Perte Total et Irréversible d'Autonomie" Margin="10" Grid.ColumnSpan="3" >
            <StackPanel HorizontalAlignment="Center" Margin="0,10" >
                
                <!-- Table de mortalité des hommes -->
                <UniformGrid Margin="{DynamicResource EntryGridMargin}" Columns="2">
                    <UniformGrid.Visibility>
                        <Binding Path="TableMortaliteHomme_IsUsed">
                            <Binding.Converter>
                                <BooleanToVisibilityConverter />
                            </Binding.Converter>
                        </Binding>
                    </UniformGrid.Visibility>
                    <TextBlock Text="Table de mortalité des hommes" Margin="{DynamicResource EntryLabelMargin}" HorizontalAlignment="{DynamicResource EntryLabelHorizontalAlignment}" VerticalAlignment="{DynamicResource EntryLabelVerticalAlignment}" />
                    <ComboBox
                        Width="{DynamicResource EntryValueWidth}"
                        Margin="{DynamicResource EntryValueMargin}"
                        HorizontalAlignment="{DynamicResource EntryValueHorizontalAlignment}"
                        VerticalAlignment="{DynamicResource EntryValueVerticalAlignment}"
                        Style="{DynamicResource OMANE_cbx}" ItemsSource="{Binding TablesMortaliteHomme, Mode=OneWay}" 
                        SelectedItem="{Binding TableMortaliteHommeSelectionne}" >

                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock  Text="{Binding Path=NomTable}" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                        <ComboBox.ItemContainerStyle>
                            <Style TargetType="{x:Type ComboBoxItem}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ContentControl}">
                                            <TextBlock  Text="{Binding Path=NomTable}" Background="{TemplateBinding Background}" />
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                                <Style.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter Property="Foreground" Value="Red" />
                                    </Trigger>
                                    <Trigger Property="IsHighlighted" Value="True">
                                        <Setter Property="Foreground" Value="White" />
                                        <Setter Property="Background" Value="Violet" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </ComboBox.ItemContainerStyle>
                    </ComboBox>
                </UniformGrid>

                <!-- Table de mortalité des femmes -->
                <UniformGrid Margin="{DynamicResource EntryGridMargin}" Columns="2" >
                    <UniformGrid.Visibility>
                        <Binding Path="TablesMortaliteFemme_IsUsed">
                            <Binding.Converter>
                                <BooleanToVisibilityConverter />
                            </Binding.Converter>
                        </Binding>
                    </UniformGrid.Visibility>
                    <TextBlock Text="Table de mortalité des femmmes" Margin="{DynamicResource EntryLabelMargin}" HorizontalAlignment="{DynamicResource EntryLabelHorizontalAlignment}" VerticalAlignment="{DynamicResource EntryLabelVerticalAlignment}" />
                    <ComboBox 
                        Width="{DynamicResource EntryValueWidth}" 
                        Margin="{DynamicResource EntryValueMargin}" 
                        HorizontalAlignment="{DynamicResource EntryValueHorizontalAlignment}" 
                        VerticalAlignment="{DynamicResource EntryValueVerticalAlignment}" 
                        Style="{DynamicResource OMANE_cbx}" ItemsSource="{Binding TablesMortaliteFemme, Mode=OneWay}" 
                        SelectedItem="{Binding TableMortaliteFemmeSelectionne}" >

                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock  Text="{Binding Path=NomTable}" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                        <ComboBox.ItemContainerStyle>
                            <Style TargetType="{x:Type ComboBoxItem}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ContentControl}">
                                            <TextBlock  Text="{Binding Path=NomTable}" Background="{TemplateBinding Background}" />
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                                <Style.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter Property="Foreground" Value="Red" />
                                    </Trigger>
                                    <Trigger Property="IsHighlighted" Value="True">
                                        <Setter Property="Foreground" Value="White" />
                                        <Setter Property="Background" Value="Violet" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </ComboBox.ItemContainerStyle>
                    </ComboBox>
                </UniformGrid>

                <!-- Age de fin  de la  garantie décès -->
                <UniformGrid Margin="{DynamicResource EntryGridMargin}" Columns="2" >
                    <UniformGrid.Visibility>
                        <Binding Path="AgeFinGarantieDeces_IsUsed">
                            <Binding.Converter>
                                <BooleanToVisibilityConverter />
                            </Binding.Converter>
                        </Binding>
                    </UniformGrid.Visibility>
                    <TextBlock Text="Age de fin  de la  garantie décès" Margin="{DynamicResource EntryLabelMargin}" HorizontalAlignment="{DynamicResource EntryLabelHorizontalAlignment}" VerticalAlignment="{DynamicResource EntryLabelVerticalAlignment}" />
                    <!--<Theme:NumericEditor Style="{StaticResource AgeEditor}" Value="{Binding AgeFinGarantieDeces}"/>-->
                    <StackPanel Orientation="Horizontal" DataContext="{Binding AgeFinGarantieDecesSegmente}" HorizontalAlignment="{DynamicResource EntryValueHorizontalAlignment}" VerticalAlignment="{DynamicResource EntryValueVerticalAlignment}">
                        <Theme:NumericEditor Style="{StaticResource AgeEditor}" Value="{Binding UniqueValue}" IsEnabled="{Binding NotUsedSegmentation}"/>
                        <RadioButton DataContext="{Binding}" Margin="5" VerticalAlignment="Center"  Checked="RadioButton_Checked" GroupName="Segments" IsThreeState="False" IsChecked="{Binding Selected, Mode=TwoWay}" Focusable="False" IsTabStop="False" />
                        <ToggleButton Style="{StaticResource SegmentEditorToggleButtonStyle}" IsChecked="{Binding NotUsedSegmentation}" Focusable="False" IsTabStop="False" />
                    </StackPanel>
                </UniformGrid>

                <!-- Présence de la  garantie décès PTIA -->
                <UniformGrid Margin="{DynamicResource EntryGridMargin}" Columns="2" >
                    <UniformGrid.Visibility>
                        <Binding Path="PresenceGarantiePTIA_IsUsed">
                            <Binding.Converter>
                                <BooleanToVisibilityConverter />
                            </Binding.Converter>
                        </Binding>
                    </UniformGrid.Visibility>
                    <TextBlock Text="Présence de la  garantie décès PTIA" Margin="{DynamicResource EntryLabelMargin}" HorizontalAlignment="{DynamicResource EntryLabelHorizontalAlignment}" VerticalAlignment="{DynamicResource EntryLabelVerticalAlignment}" />
                    <StackPanel Orientation="Horizontal" DataContext="{Binding PresenceGarantiePtia}" Margin="{DynamicResource EntryValueMargin}" HorizontalAlignment="{DynamicResource EntryValueHorizontalAlignment}" VerticalAlignment="{DynamicResource EntryValueVerticalAlignment}">
                        <ComboBox Width="{DynamicResource EntryValueWidth}"  
                                  Style="{DynamicResource OMANE_cbx}"
                                  ItemStringFormat="Oui;Non"
                                  SelectedValue="{Binding UniqueValue}" 
                                                               
                                  SelectedValuePath="Left"
                                  IsEnabled="{Binding NotUsedSegmentation}">  
                           
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Right}" />
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                            <local:Pair Left="True" Right="Oui" />
                                    <local:Pair Left="False" Right="Non" />
                        </ComboBox>
                        <RadioButton DataContext="{Binding}" VerticalAlignment="Center" Margin="6,5,5,5"  Checked="RadioButton_Checked" IsChecked="{Binding Selected, Mode=TwoWay}" GroupName="Segments" IsThreeState="False" Focusable="False" IsTabStop="False" />
                        <ToggleButton  Style="{StaticResource SegmentEditorToggleButtonStyle}" IsChecked="{Binding NotUsedSegmentation}" Unchecked="ToggleButton_Unchecked" Height="25.09" Width="25.09" Focusable="False" IsTabStop="False" />
                    </StackPanel>
                </UniformGrid>

                <!-- Tarif PTIA ( en % du tarif décès ) -->
                <UniformGrid Margin="{DynamicResource EntryGridMargin}" Columns="2" >
                    <UniformGrid.Visibility>
                        <Binding Path="tarifPTIA_IsUsed">
                            <Binding.Converter>
                                <BooleanToVisibilityConverter />
                            </Binding.Converter>
                        </Binding>
                    </UniformGrid.Visibility>
                    <TextBlock Text="Tarif PTIA ( en % du tarif décès )" Margin="{DynamicResource EntryLabelMargin}" HorizontalAlignment="{DynamicResource EntryLabelHorizontalAlignment}" VerticalAlignment="{DynamicResource EntryLabelVerticalAlignment}" />
                    <StackPanel Orientation="Horizontal" DataContext="{Binding TarifPtia}" HorizontalAlignment="{DynamicResource EntryValueHorizontalAlignment}" VerticalAlignment="{DynamicResource EntryValueVerticalAlignment}">
                        <Theme:NumericEditor Style="{StaticResource PercentageEditor}" Value="{Binding UniqueValue}" IsEnabled="{Binding NotUsedSegmentation}"/>
                        <RadioButton DataContext="{Binding}" Margin="5" VerticalAlignment="Center"  Checked="RadioButton_Checked" GroupName="Segments" IsThreeState="False" IsChecked="{Binding Selected, Mode=TwoWay}" Focusable="False" IsTabStop="False" />
                        <ToggleButton Style="{StaticResource SegmentEditorToggleButtonStyle}" IsChecked="{Binding NotUsedSegmentation}" Focusable="False" IsTabStop="False" />
                    </StackPanel>
                </UniformGrid>

                <!-- Majoration prudentielle des montants de sinistres DC/PTIA -->
                <UniformGrid Margin="{DynamicResource EntryGridMargin}" Columns="2" >
                    <UniformGrid.Visibility>
                        <Binding Path="MajorationPrudentielle_IsUsed">
                            <Binding.Converter>
                                <BooleanToVisibilityConverter />
                            </Binding.Converter>
                        </Binding>
                    </UniformGrid.Visibility>
                    <TextBlock Text="Majoration prudentielle des montants de sinistres DC/PTIA" Margin="{DynamicResource EntryLabelMargin}" HorizontalAlignment="{DynamicResource EntryLabelHorizontalAlignment}" VerticalAlignment="{DynamicResource EntryLabelVerticalAlignment}" />
                    <StackPanel Orientation="Horizontal" DataContext="{Binding MajorationPrudentielle}" HorizontalAlignment="{DynamicResource EntryValueHorizontalAlignment}" VerticalAlignment="{DynamicResource EntryValueVerticalAlignment}">
                        <Theme:NumericEditor Style="{StaticResource PercentageEditor}" Value="{Binding UniqueValue}" IsEnabled="{Binding NotUsedSegmentation}"/>
                        <RadioButton DataContext="{Binding}" Margin="5" VerticalAlignment="Center" Checked="RadioButton_Checked" GroupName="Segments" IsThreeState="False" IsChecked="{Binding Selected, Mode=TwoWay}" Focusable="False" IsTabStop="False"/>
                        <ToggleButton Style="{StaticResource SegmentEditorToggleButtonStyle}" IsChecked="{Binding NotUsedSegmentation}" Unchecked="ToggleButton_Unchecked" Focusable="False" IsTabStop="False" />
                    </StackPanel>
                </UniformGrid>

                <!-- Sélection médicale -->
                <UniformGrid Margin="{DynamicResource EntryGridMargin}" Columns="2" >
                    <UniformGrid.Visibility>
                        <Binding Path="SelectionMedicale_IsUsed">
                            <Binding.Converter>
                                <BooleanToVisibilityConverter />
                            </Binding.Converter>
                        </Binding>
                    </UniformGrid.Visibility>
                    <TextBlock Text="Sélection médicale" 
                               Margin="{DynamicResource EntryLabelMargin}" 
                               HorizontalAlignment="{DynamicResource EntryLabelHorizontalAlignment}" 
                               VerticalAlignment="{DynamicResource EntryLabelVerticalAlignment}" />
                    
                    <StackPanel Orientation="Horizontal"
                                DataContext="{Binding SelectionMedicale}" 
                                HorizontalAlignment="{DynamicResource EntryValueHorizontalAlignment}" 
                                VerticalAlignment="{DynamicResource EntryValueVerticalAlignment}">
                        <Theme:NumericEditor Value="{Binding DeroulementMax}" Style="{StaticResource SelMedicaleEditor}" Format="0">
                        </Theme:NumericEditor>
						<RadioButton DataContext="{Binding}" 
                                     Margin="5" 
                                     VerticalAlignment="Center" 
                                     Checked="RadioButton_Checked" 
                                     GroupName="Segments" 
                                     IsThreeState="False" 
                                     IsChecked="{Binding Selected, Mode=TwoWay}" Focusable="False" IsTabStop="False"/>
                        <ToggleButton Style="{StaticResource SegmentEditorToggleButtonStyle}" Height="25.09" Focusable="False" IsTabStop="False" />
                    </StackPanel>
                </UniformGrid>
                
            </StackPanel>
        </GroupBox>
        <GridSplitter HorizontalAlignment="Stretch" Grid.Row="1" Grid.ColumnSpan="3" ResizeDirection="Rows" />
        <GridSplitter ResizeDirection="Columns" HorizontalAlignment="Stretch" Grid.Row="2" Grid.Column="1" />
        <DockPanel Grid.Row="2" 
                    Visibility="Visible" 
                    DataContext="{Binding CurrentSegmentableValue}"
                    >
            <DockPanel.Resources>
                <CollectionViewSource x:Key="VariablesView"  Source="{Binding AvailableVariables}">
                    <CollectionViewSource.GroupDescriptions>
                        <PropertyGroupDescription PropertyName="Type"></PropertyGroupDescription>
                    </CollectionViewSource.GroupDescriptions>
                </CollectionViewSource>
            </DockPanel.Resources>
            <TextBlock TextWrapping="Wrap" Text="Variables de  Segmentation" Margin="5,5,0,5" DockPanel.Dock="Top"/>
            <ListView x:Name="variablesLst" 
                      BorderBrush="{x:Null}"       
                      ItemsSource="{Binding Source={StaticResource VariablesView}}" 
                      DockPanel.Dock="Bottom"
                      HorizontalContentAlignment="Stretch" SelectionMode="Multiple">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Description}" />
                    </DataTemplate>
                </ListView.ItemTemplate>
                <ListView.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}">
                        <EventSetter Event="UIElement.PreviewMouseLeftButtonDown" Handler="VariableStyle_PreviewMouseLeftButtonDown" />
                        <Setter Property="HorizontalAlignment" Value="Stretch" />
                    </Style>
                </ListView.ItemContainerStyle>
                <!--<ListView.Visibility>
                    <Binding Path="UsedSegmentation" FallbackValue="Hidden">
                        <Binding.Converter>
                            <BooleanToVisibilityConverter />
                        </Binding.Converter>
                    </Binding>
                </ListView.Visibility>-->
                <ListView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.ContainerStyle>
                            <Style TargetType="{x:Type GroupItem}">
                                <Setter Property="Margin" Value="0,0,0,5"></Setter>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type GroupItem}">
                                            <Expander IsExpanded="True" BorderBrush="#FFA4B97F" BorderThickness="0,0,0,1">
                                                <Expander.Header>
                                                    <DockPanel>
                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=Name, Converter={StaticResource TypeNameConverter}}"
                                                                   Margin="5,0,0,0" Width="100" />
                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}" />
                                                    </DockPanel>
                                                </Expander.Header>
                                                <Expander.Content>
                                                    <ItemsPresenter />
                                                </Expander.Content>
                                            </Expander>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>

                        </GroupStyle.ContainerStyle>
                    </GroupStyle>
                </ListView.GroupStyle>
                <ListView.View>
                    <GridView>
                        <GridView.Columns>
                            <GridViewColumn Header="                       ">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <Image Margin="0,0,5,0" Source="{Binding Type, Converter={StaticResource TypeNameToIconConverter}}"></Image>
                                            <TextBlock FontWeight="Regular" Text="{Binding Description}"></TextBlock>
                                        </StackPanel>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
        </DockPanel>
        <DockPanel 
            Grid.Row="2" 
            Grid.Column="3" 
            DataContext="{Binding CurrentSegmentableValue}" 
            Name="segmentsDockPanel">
            <TextBlock TextWrapping="Wrap"  Margin="5" DockPanel.Dock="Top">
                <TextBlock.Inlines>
                    <Run Text="Paramétrage : " />
                    <Run Text="{Binding Name, FallbackValue=Defaut}" />
                </TextBlock.Inlines>
            </TextBlock>
            <DataGrid                
                DockPanel.Dock="Bottom" 
                AllowDrop="True"  
                ItemsSource="{Binding Table}"
                ColumnWidth="*"
                Drop="DataGrd_Drop"               
                AutoGenerateColumns="True" 
                CanUserAddRows="False" 
                CanUserDeleteRows="False" 
                Name="segmentsGrd"
                >
                <DataGrid.ColumnHeaderStyle>
                    <Style TargetType="{x:Type DataGridColumnHeader}">
                        <Setter Property="VerticalContentAlignment" Value="Center"/>
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0" Text="{Binding}"  HorizontalAlignment="Center" VerticalAlignment="Center" />
                                        <Button Grid.Column="1" 
                                                Content="X" 
                                                Padding="5" 
                                                DataContext="{Binding}" 
                                                Click="DeleteButton_Click"
                                               >
                                            <Button.Visibility>
                                                <Binding RelativeSource="{RelativeSource AncestorType=DataGridColumnHeader}" 
                                                         Path="Column" 
                                                         Converter="{StaticResource ColumnToVisibilityConverter}" >
                                                </Binding>
                                            </Button.Visibility>
                                        </Button>
                                    </Grid>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </DataGrid.ColumnHeaderStyle>
                <!--<DataGrid.Visibility>
                    <Binding Path="UsedSegmentation" FallbackValue="Hidden">
                        <Binding.Converter>
                            <BooleanToVisibilityConverter />
                        </Binding.Converter>
                    </Binding>
                </DataGrid.Visibility>-->         
            </DataGrid>
        </DockPanel>
    </Grid>
</UserControl>
